package com.yungu.swift.admin.route.finance;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.utils.ExcelUtil;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.order.model.param.AdminRechargeBillPageParam;
import com.yungu.swift.order.model.vo.AdminRechargeBillVo;
import com.yungu.swift.order.service.OrderRechargeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : cuixiuyin
 * @date : 2019/8/20
 */
@RestController
@RequestMapping("/admin/v1/finance/orderRecharge")
@Api(value = "【财务管理】", tags = "充值支付")
public class OrderRechargeAdmin {

    @Reference
    private OrderRechargeService orderRechargeService;


    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    @ApiOperation(value = "充值支付信息分页", httpMethod = "POST")
    public ResponseData<PageVo<AdminRechargeBillVo>> queryPage(@RequestBody AdminRechargeBillPageParam billPageParam) {
        return orderRechargeService.rechargeBillPage(billPageParam);
    }

    @RequestMapping(value = "/export", method = RequestMethod.POST)
    @ApiOperation(value = "充值支付信息导出", httpMethod = "POST")
    public void export(@RequestBody AdminRechargeBillPageParam billPageParam, HttpServletResponse response) {
        List<AdminRechargeBillVo> list = orderRechargeService.rechargeBillExport(billPageParam).getData();
        Map<Object, Object>[] dictionaryMapArray = new Map[9];
        //充值方式字典
        dictionaryMapArray[3] = new HashMap<>(2);
        dictionaryMapArray[3].put(1, "微信充值");
        dictionaryMapArray[3].put(2, "支付宝充值");
        //充值状态字典
        dictionaryMapArray[8] = new HashMap<>(2);
        dictionaryMapArray[8].put(0, "充值失败");
        dictionaryMapArray[8].put(1, "充值成功");
        ExcelUtil.export(response, "充值支付", list, 9,
                new String[]{"充值创建时间", "充值完成时间", "流水号", "充值方式", "乘客信息", "乘客手机号码",
                        "充值金额（元）", "赠送金额（元）", "充值状态"},
                new String[]{"createOn", "finishTime", "平台流水号：#platformSerialNumber#第三方流水号：#paySerialNumber#", "payType", "name", "mobile",
                        "rechargeAmount", "giftAmount", "status"},
                dictionaryMapArray);
    }

    @RequestMapping(value = "/count", method = RequestMethod.POST)
    @ApiOperation(value = "充值支付信息汇总", httpMethod = "POST")
    public ResponseData<Map<String, Object>> getCountAndMoney(@RequestBody AdminRechargeBillPageParam billPageParam) {
        return orderRechargeService.rechargeBillCount(billPageParam);
    }
}
